<template>
  <div class="page">
    <div class="login-panel">
      <div class="title">
        <span class="big">Mtime</span>
        <span class="small">影片库管理系统</span>
      </div>
      <div class="login-form">
        <div class="form-item">
          <div class="label">登录账户：</div>
          <input class="input" v-model="username" type="text" placeholder="请输入登录账户" />
        </div>
        <div class="form-item">
          <div class="label">账户密码：</div>
          <input class="input" v-model="password" type="password" placeholder="请输入账户密码" />
        </div>
        <div class="form-item flex-row">
          <div class="login-button" @click="dologin('/admin')">进入后台管理系统</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: '',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    validateLogin () {
      if (this.username == "") {
        return false;
      }
      if (this.password == "") {
        return false;
      }
      return true;
    },
    async dologin (path) {
      if (!this.validateLogin()) return;
      localStorage.removeItem("usertoken");
      let response = await this.$api.user.login({
          username: this.username,
          password: this.password
        },
      )
      console.log("登录API响应：", response);
      // if (response.status == 200) {
        var data = response.data;
        localStorage.setItem("usertoken", data.id_token);
        this.$router.push(path);
      // }
    }
  },
}
</script>

<style scoped>
body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  padding: 0;
  margin: 0;
}
.page {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url('https://demos.creative-tim.com/light-bootstrap-dashboard-pro-angular2/assets/img/full-screen-image-3.jpg');
  background-repeat: no-repeat;
  background-size: cover;
}
.login-panel {
  background-color: #fff;
  width: 450px;
  height: 400px;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 10px;
}

.login-panel .title {
  margin-top: 20px;
  font-weight: 600;
  color: #fb404b;
}
.title .big {
  font-size: 180%;
}
.title .small {
  color: #888;
  font-size: 120%;
}
.login-form {
  margin-top: 20px;
  width: 90%;
}
.login-form .form-item {
  display: flex;
  flex-direction: column;
  margin-top: 15px;
}
.form-item .label {
  margin-top: 15px;
  margin-bottom: 10px;
  font-size: 110%;
}

.form-item .input {
  line-height: 32px;
  border: none;
  border-bottom: 1px solid #888888;
  outline: none;
  font-size: 105%;
}
.login-button {
  width: 100px;
  padding: 10px 15px;
  text-align: center;
  background-color: #fb404b;
  color: #fff;
  margin: 20px auto;
  cursor: pointer;
}
</style>
